<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Edge Panel</title>
    <style>
        html, body {
            margin: 0;
            padding: 0;
            background: transparent;
            height: 100%;
            width: 100%;
            overflow: hidden;
        }

        /* webview 最底层 */
        #webview-container {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        #webview {
            width: 100%;
            height: 100%;
            border: none;
        }

        /* 标题栏 */
        #title-bar {
            width: 100%;
            height: 32px;
            background-color: white;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid #ddd;
            -webkit-app-region: drag;
            transition: opacity 0.3s ease;
        }

        #title-bar.visible {
            opacity: 1;
        }

        #left-controls, #right-controls {
            display: flex;
            align-items: center;
            margin-right: 8px;
            gap: 8px;
            -webkit-app-region: no-drag;
        }

    </style>
</head>
<body>
<div id="container">
    <div id="title-bar">
        <div id="left-controls">
            <button id="back">❮</button>
            <button id="forward">❯</button>
            <button id="reload" onclick="window.location.reload()">⭮</button>
        </div>
        <div id="right-controls">
            <button onclick="minimize()">➖</button>
            <button onclick="winClose()">❌</button>
        </div>
    </div>

    <div id="webview-container">
        <webview id="webview" allowpopups></webview>
    </div>
</div>

<script>
    const urlParams = new URLSearchParams(window.location.search);
    const url = urlParams.get('url');
    const winName = urlParams.get('winName');

    const webview = document.getElementById('webview');
    webview.src = url.startsWith("http") ? url : "http://" + url;

    const backBtn = document.getElementById('back');
    const forwardBtn = document.getElementById('forward');

    backBtn.addEventListener('click', () => {
        if (webview.canGoBack()) webview.goBack();
    });

    forwardBtn.addEventListener('click', () => {
        if (webview.canGoForward()) webview.goForward();
    });

    webview.addEventListener('new-window', (e) => {
        webview.src = e.url;
    });

    function minimize() {
        window.utools.sendToParent('minimize', winName);
    }

    function winClose() {
        window.utools.sendToParent('win-close', winName);
        window.close();
    }
</script>
</body>
</html>
